package com.feng.demo.xstream;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
/**
 * 使用Annotation实现XStreame对Java Object的转换
 * @author bing
 *
 */
@SuppressWarnings("deprecation")
@XStreamAlias("message")
public class Person extends XmlLangObject{
	@XStreamAlias("nick")
	private String name;
	@XStreamImplicit(itemFieldName="part") 
	private List<String> content;
	@XStreamConverter(SingleValueCalendarConverter.class) 
	private Date birth;
	public Person(String names,Date date,String... contents) {
		setName(names);
		setContent(Arrays.asList(contents));
		setBirth(date);
	}

	public static void main(String[] args) {
		/*XStream stream = new XStream();
		stream.processAnnotations(Person.class);
		//Annotations.configureAliases(stream, Person.class);
		Person msg = new Person("中国","a","b","c");
		System.out.println(stream.toXML(msg));
		System.out.println(stream.toXML(msg));*/
		
		Person msg = new Person("中国",new Date(System.currentTimeMillis()),"a","b","c");
		//System.out.println(stream.toXML(msg));
		System.out.println(msg.toXml());
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param content the content to set
	 */
	public void setContent(List<String> content) {
		this.content = content;
	}

	/**
	 * @return the content
	 */
	public List<String> getContent() {
		return content;
	}

	/**
	 * @param birth the birth to set
	 */
	public void setBirth(Date birth) {
		this.birth = birth;
	}

	/**
	 * @return the birth
	 */
	public Date getBirth() {
		return birth;
	}
}
